<template>
  <a-card :bordered="false" class="card-area">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <!-- 搜索区域 -->
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="科室" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}">
              <a-select v-model="queryParam.departmentId" placeholder="请选择排班的科室">
                <a-select-option value=''>请选择</a-select-option>
                <a-select-option v-for="item in departOption" :key="item.key" :value="item.value">{{ item.title }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator"  style="margin-top: 5px">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">
          批量操作 <a-icon type="down" />
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleWeek(record)">查看安排</a>
          <a-divider type="vertical" />
          <a @click="handleUpdate(record)">新增排班人员</a>
          <a-divider type="vertical" />

           <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
           </a-popconfirm>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <edit-modal ref="modalForm" @ok="modalFormOk"></edit-modal>
    <week-list-modal ref="weekModalForm"></week-list-modal>
  </a-card>
</template>

<script>
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EditModal from './modules/EditModal'
  import WeekListModal from './modules/WeekListModal'
  import JDate from '@comp/jeecg/JDate'
  import { queryMyDepartTreeList } from '@api/api'
  import { getAction } from '@api/manage'

  export default {
    name: "DepartList",
    mixins:[JeecgListMixin],
    components: {
      EditModal,
      WeekListModal,
      JDate
    },
    data () {
      return {
        description: '排班列表页面',
        // 查询条件
        queryParam: {"departmentName":""},
        departOption:[],
        // 表头
        columns: [
          {
            title: '排班方案',
            align:"center",
            dataIndex: 'planName'
          },
          {
            title: '科室名称',
            align:"center",
            dataIndex: 'departmentName'
          },{
            title: '排班开始时间',
            align:"center",
            dataIndex: 'startTimeThisWeek'
          },{
            title: '排班结束时间',
            align:"center",
            dataIndex: 'endTimeThisWeek'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/his/scheduling/list",
          delete: "/his/scheduling",
          deleteBatch: "/his/scheduling/deleteBatch",
        },
      }
    },
    computed: {
    },
    created() {
       this.initRequestData();
    },
    methods: {
      initRequestData() {
        let that = this
        queryMyDepartTreeList().then((res) => {
            if (res.success && res.result) {
              that.departOption = res.result
            }
          }
        )
      },
      handleWeek: function (record) {
        this.$refs.weekModalForm.add(record);
        this.$refs.weekModalForm.title = "排班计划-"+record.departmentName;
      },
      handleAdd: function () {
        this.$router.push({path:'/ischeduling/Edit'})
      },
      handleUpdate: function (record) {
        this.$router.push({path:'/ischeduling/Update', query: { id: record.id } })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>